﻿<sap:ActivityDesigner x:Class="MyData.Activities.Designers.SharePointItemsDesigner"
   xmlns:s="clr-namespace:System;assembly=mscorlib"   
   xmlns:net="clr-namespace:System.Net;assembly=System" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
    xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation"
    xmlns:sapc="clr-namespace:System.Activities.Presentation.Converters;assembly=System.Activities.Presentation"  
    xmlns:Model="clr-namespace:System.Activities.Presentation.Model;assembly=System.Activities.Presentation"  
    xmlns:local="clr-namespace:MyData.Activities"
    Collapsible="True" >

    <sap:ActivityDesigner.Resources>
        <sapc:ArgumentToExpressionConverter x:Key="ArgumentToExpressionConverter" />
        <sapc:ModelToObjectValueConverter x:Key="ModelToObjectValueConverter" />

        <ObjectDataProvider x:Key="SharePointOperationEnumValues" MethodName="GetValues" ObjectType="{x:Type s:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="local:SharePointOperationEnum" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        
        <DataTemplate x:Key="ShowAsCollapsed">
            <TextBlock Foreground="Gray">
                <TextBlock.Text>
                     <MultiBinding StringFormat="Find for {0}">
                        <Binding Path="ModelItem.ListTitle.Expression" />
                       
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </DataTemplate>
        <DataTemplate x:Key="ShowAsExpanded">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>

                <Expander Header="SharePoint Context" Height="Auto"  HorizontalAlignment="Left" Margin="12,12,0,0" Name="SharePoint" VerticalAlignment="Center" Width="235" IsExpanded="True">
                    <Grid Height="Auto">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="45*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <TextBlock Height="Auto" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" Margin="0,0,0,0" Text="Credentials" 
                                   VerticalAlignment="Center"  Width="55" />

                        <sapv:ExpressionTextBox GotFocus="ExpressionTextBox_GotFocus" HintText="Credentials" 
                            Grid.Row ="0" Grid.Column="1"   MaxWidth="150" MinWidth="150" Margin="5"
                            OwnerActivity="{Binding Path=ModelItem}"
                            Expression="{Binding Path=ModelItem.NetworkCredential, Mode=TwoWay, 
                            Converter={StaticResource ArgumentToExpressionConverter}, 
                            ConverterParameter=In }"
                            ExpressionType="net:ICredentials"/>

                        <TextBlock Height="Auto" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" Margin="0,0,0,0" Text="Url" VerticalAlignment="Center" />

                        <sapv:ExpressionTextBox GotFocus="ExpressionTextBox_GotFocus" HintText="SharePont 2010 Url" 
                            Grid.Row ="1" Grid.Column="1"   MaxWidth="150" MinWidth="150" Margin="5"
                            OwnerActivity="{Binding Path=ModelItem}"
                            Expression="{Binding Path=ModelItem.Url, Mode=TwoWay, 
                            Converter={StaticResource ArgumentToExpressionConverter}, 
                            ConverterParameter=In }"
                            ExpressionType="s:String"/>


                        <TextBlock Height="Auto" Grid.Row="2" Grid.Column="0"  HorizontalAlignment="Left" Margin="0,0,0,0" 
                                   VerticalAlignment="Center" Text="List Title"  />

                        <sapv:ExpressionTextBox GotFocus="ExpressionTextBox_GotFocus" HintText="List Title" 
                            Grid.Row ="2" Grid.Column="1"   MaxWidth="150" MinWidth="150" Margin="5"
                            OwnerActivity="{Binding Path=ModelItem}"
                            Expression="{Binding Path=ModelItem.ListTitle, Mode=TwoWay, 
                            Converter={StaticResource ArgumentToExpressionConverter}, 
                            ConverterParameter=In }"
                            ExpressionType="s:String"/>
                        
                         <TextBlock Height="Auto" Grid.Row="3" Grid.Column="0"  HorizontalAlignment="Left" Margin="0,0,0,0" 
                                   VerticalAlignment="Center" Text="View Fields"  />

                        <sapv:ExpressionTextBox GotFocus="ExpressionTextBox_GotFocus" HintText="View Fields" 
                            Grid.Row="3" Grid.Column="1"   MaxWidth="150" MinWidth="150" Margin="5"
                            OwnerActivity="{Binding Path=ModelItem}"
                            Expression="{Binding Path=ModelItem.ViewFields, Mode=TwoWay, 
                            Converter={StaticResource ArgumentToExpressionConverter}, 
                            ConverterParameter=In }"
                            Loaded="ListExpressionTextBox_Loaded"
                            ExpressionType="s:Object"/>                       
             

                        <TextBlock Height="Auto" Grid.Row="4" Grid.Column="0"  HorizontalAlignment="Left" Margin="0,0,0,0" 
                                   VerticalAlignment="Center" Text="Operation"  />

                        <ComboBox x:Name="comboSharePointEnum" ItemsSource="{Binding Source={StaticResource SharePointOperationEnumValues}}" 
                          SelectedValue="{Binding Path=ModelItem.Operation, Mode=TwoWay, 
                        Converter={StaticResource ModelToObjectValueConverter}}" VerticalAlignment="Center" Grid.Row="4" Grid.Column="4" Margin="4"></ComboBox>
                        
                        <Grid x:Name="fieldsGrid" Grid.ColumnSpan="2" Grid.Row="5" Grid.Column="0">
                            <Grid.Style>
                                <Style TargetType="Grid">
                                    <Setter Property="Visibility" Value="Collapsed" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding ElementName=comboSharePointEnum, Path=SelectedItem}" Value="Update">
                                            <Setter Property="Visibility"  Value="Visible"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Grid.Style>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="45*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>

                            <TextBlock Height="Auto"  Grid.Row ="0" Grid.Column="0"  HorizontalAlignment="Left" Margin="0,0,0,0" 
                                   VerticalAlignment="Center" Text="Fields"  />

                        <sapv:ExpressionTextBox GotFocus="ExpressionTextBox_GotFocus" HintText="Fields" 
                            Grid.Row ="0" Grid.Column="1"   MaxWidth="150" MinWidth="150" Margin="5"
                            OwnerActivity="{Binding Path=ModelItem}"
                            Expression="{Binding Path=ModelItem.FieldValues, Mode=TwoWay, 
                            Converter={StaticResource ArgumentToExpressionConverter}, 
                            ConverterParameter=In }"
                            ExpressionType="s:Object" Loaded="DictionaryExpressionTextBox_Loaded"/>                                             
                        </Grid>
                    </Grid>
                </Expander>

                <sap:WorkflowItemsPresenter
                Grid.Row ="1" Grid.Column="0" Grid.ColumnSpan="2"                                            
                Margin="5" MinHeight="30" AllowedItemType="{x:Type TypeName=local:CamlWhere}" 
                Items="{Binding Path=ModelItem.Activities}">
                    <sap:WorkflowItemsPresenter.SpacerTemplate>
                        <DataTemplate>
                            <TextBlock Background="GhostWhite" Width="200" HorizontalAlignment="Center" TextAlignment="Center" FontStyle="Italic">Drop Where Here</TextBlock>
                        </DataTemplate>
                    </sap:WorkflowItemsPresenter.SpacerTemplate>

                    <sap:WorkflowItemsPresenter.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical" />
                        </ItemsPanelTemplate>
                    </sap:WorkflowItemsPresenter.ItemsPanel>
                </sap:WorkflowItemsPresenter>

               
            </Grid>
        </DataTemplate>
        <Style x:Key="StyleWithCollapse" TargetType="{x:Type ContentPresenter}">
            <Setter Property="ContentTemplate" 
                Value="{DynamicResource ShowAsExpanded}"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=ShowExpanded}" Value="False">
                    <Setter Property="ContentTemplate" 
                        Value="{DynamicResource ShowAsCollapsed}"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </sap:ActivityDesigner.Resources>

    <sap:ActivityDesigner.Icon>
        <DrawingBrush>
            <DrawingBrush.Drawing>
                <ImageDrawing>
                    <ImageDrawing.Rect>
                        <Rect Location="0,0" Size="16,16" ></Rect>
                    </ImageDrawing.Rect>
                    <ImageDrawing.ImageSource>
                        <BitmapImage UriSource="SharePointItems.png" />
                    </ImageDrawing.ImageSource>
                </ImageDrawing>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </sap:ActivityDesigner.Icon>
    <Grid>
        <ContentPresenter Style="{DynamicResource StyleWithCollapse}" 
            Content="{Binding}"/>
    </Grid>

</sap:ActivityDesigner>
